// Copyright (c) Microsoft Corporation.  All rights reserved.
#pragma once

//
// CTextHost
//
// This is an implementation of ITextHost of RichEdit control.
//

#include <imm.h>
#include <textserv.h>
#include <tom.h>

class CTextHost :
    public CComObjectRoot,
    public ITextHost
{
public:
    CTextHost();
    
    virtual ~CTextHost();
    
    BEGIN_COM_MAP(CTextHost)
        COM_INTERFACE_ENTRY_IID(IID_ITextHost, ITextHost)
    END_COM_MAP()   

    // ITextHost
    virtual HDC         TxGetDC();
    virtual INT         TxReleaseDC(HDC hdc);
    virtual BOOL        TxShowScrollBar(INT fnBar, BOOL fShow);
    virtual BOOL        TxEnableScrollBar (INT fuSBFlags, INT fuArrowflags);
    virtual BOOL        TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw);
    virtual BOOL        TxSetScrollPos (INT fnBar, INT nPos, BOOL fRedraw);
    virtual void        TxInvalidateRect(LPCRECT prc, BOOL fMode);
    virtual void        TxViewChange(BOOL fUpdate);
    virtual BOOL        TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight);
    virtual BOOL        TxShowCaret(BOOL fShow);
    virtual BOOL        TxSetCaretPos(INT x, INT y);
    virtual BOOL        TxSetTimer(UINT idTimer, UINT uTimeout);
    virtual void        TxKillTimer(UINT idTimer);
    virtual void        TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll);
    virtual void        TxSetCapture(BOOL fCapture);
    virtual void        TxSetFocus();
    virtual void        TxSetCursor(HCURSOR hcur, BOOL fText);
    virtual BOOL        TxScreenToClient(LPPOINT lppt);
    virtual BOOL        TxClientToScreen(LPPOINT lppt);
    virtual HRESULT     TxActivate(LONG* plOldState);
    virtual HRESULT     TxDeactivate(LONG lNewState);
    virtual HRESULT     TxGetClientRect(LPRECT prc);
    virtual HRESULT     TxGetViewInset(LPRECT prc);
    virtual HRESULT     TxGetCharFormat(const CHARFORMATW** ppCF);
    virtual HRESULT     TxGetParaFormat(const PARAFORMAT** ppPF);
    virtual COLORREF    TxGetSysColor(int nIndex);
    virtual HRESULT     TxGetBackStyle(TXTBACKSTYLE* pstyle);
    virtual HRESULT     TxGetMaxLength(DWORD* plength);
    virtual HRESULT     TxGetScrollBars(DWORD* pdwScrollBar);
    virtual HRESULT     TxGetPasswordChar(__out_ecount(1) TCHAR* pch);
    virtual HRESULT     TxGetAcceleratorPos(LONG* pcp);
    virtual HRESULT     TxGetExtent(LPSIZEL lpExtent);
    virtual HRESULT     OnTxCharFormatChange (const CHARFORMATW* pcf);
    virtual HRESULT     OnTxParaFormatChange (const PARAFORMAT* ppf);

    virtual HRESULT     TxGetPropertyBits(DWORD dwMask, DWORD* pdwBits);

    //@cmember Notify host of events
    virtual HRESULT     TxNotify(DWORD iNotify, void* pv);
    virtual HIMC        TxImmGetContext();
    virtual void        TxImmReleaseContext(HIMC himc);
    virtual HRESULT     TxGetSelectionBarWidth (LONG* lSelBarWidth);

    VOID SetWordWrap(BOOL bWordWrap);
    
private:
    DWORD m_dwPropBits;
};
